﻿using Codeflows;
using Codeflows.Results;
using Codeflows.Tracking;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CodeflowsTests
{
    public static class AssertHelpers
    {
        public static void ItShouldRunToCompletion<T>(this CodeflowRunResult<T> runResult) where T : Codeflow
        {
            Assert.IsTrue(runResult.Result.IsEnded);
            Assert.AreEqual(CodeflowStatus.Ended, runResult.PersistedInstance.Status);
        }

        public static void ItShouldBeSuspended<T>(this CodeflowRunResult<T> runResult) where T : Codeflow
        {
            Assert.IsTrue(runResult.Result.IsSuspended);
            Assert.AreEqual(CodeflowStatus.Suspended, runResult.PersistedInstance.Status);
        }

        public static void ItShouldBePaused<T>(this CodeflowRunResult<T> runResult) where T : Codeflow
        {
            Assert.IsTrue(runResult.Result.IsPaused);
            Assert.AreEqual(CodeflowStatus.Paused, runResult.PersistedInstance.Status);
        }

        public static void ItShouldBeAsleep<T>(this CodeflowRunResult<T> runResult) where T : Codeflow
        {
            Assert.IsTrue(runResult.Result.IsDelayedJump);
            Assert.AreEqual(CodeflowStatus.Sleeping, runResult.PersistedInstance.Status);
        }

        public static void ItShouldBeTerminated<T>(this CodeflowRunResult<T> runResult) where T : Codeflow
        {            
            Assert.AreEqual(CodeflowStatus.Terminated, runResult.PersistedInstance.Status);
        }

        public static void ItShouldEndWithValue<T>(this CodeflowRunResult<T> runResult, object expectedOutputValue) where T : Codeflow
        {
            Assert.IsTrue(runResult.Result.IsEnded);
            Assert.AreEqual(expectedOutputValue, ((EndResult)runResult.Result).Value);
        }

        public static void IsDispatched(this CodeflowAction action, int numberOfTimes)
        {
            Assert.AreEqual(numberOfTimes, action.DispatchAttemptsCount);
        }
    }
}